package com.wangh.xsap.service.impl;

import com.wangh.xsap.dto.EmployeeDto;
import com.wangh.xsap.dto.convert.EmployeeConvert;
import com.wangh.xsap.entity.Employee;
import com.wangh.xsap.mapper.LoginMapper;
import com.wangh.xsap.service.LoginService;
import com.wangh.xsap.utils.common.R;
import com.wangh.xsap.vo.EmployeeVO;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @Author：wangh
 * @Description 描述该类的功能
 * @name：LoginServiceImpl
 * @Date：2025/5/28 15:31
 */
@Service
@Slf4j
public class LoginServiceImpl implements LoginService {
    private LoginMapper loginMapper;
    private EmployeeConvert employeeConvert;

    public LoginServiceImpl(LoginMapper loginMapper, EmployeeConvert employeeConvert) {
        this.loginMapper = loginMapper;
        this.employeeConvert = employeeConvert;
    }

    @Override
    public R login(EmployeeVO employeeVO) {
        String  captcha = employeeVO.getCaptcha().toLowerCase();
//        if (captcha.equals(text)) {
            log.debug("==>验证码正确");
        Employee nameAndPassword = loginMapper.findByNameAndPassword(employeeVO.getName(), employeeVO.getPassword());
        EmployeeDto dto = employeeConvert.toDto(nameAndPassword);
        if (nameAndPassword != null) {
                return R.success("登录成功", dto);
            } else {
                return R.error("用户名或密码错误");
            }
//        } else {
//            return Result.failure("验证码错误");
//        }
    }
    @Override
    public String findByName(String name) {
        return null;
    }
}
